class LocalCache {
  // 设置缓存
  setCache(key: string, value: any, isLocalStorage: boolean = true) {
    const storage = isLocalStorage ? window.localStorage : window.sessionStorage
    storage.setItem(key, JSON.stringify(value))
  }
  // 取出缓存
  getCache(key: string, isLocalStorage: boolean = true) {
    const storage = isLocalStorage ? window.localStorage : window.sessionStorage
    const value = storage.getItem(key)
    if (value) return JSON.parse(value)
  }
  // 清除缓存
  deleteCache(key: string, isLocalStorage: boolean = true) {
    const storage = isLocalStorage ? window.localStorage : window.sessionStorage
    storage.removeItem(key)
  }
  // 清除所有缓存
  clearCache(isLocalStorage: boolean = true) {
    const storage = isLocalStorage ? window.localStorage : window.sessionStorage
    storage.clear()
  }
}

export default new LocalCache()
